/**
 * https://leetcode.cn/submissions/detail/577606628/
 * 357. 统计各位数字都不同的数字个数
 * Medium, 黄伟杰 2024.11.02
 * 数位DP
 */
#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int countNumbersWithUniqueDigits(int n)
    {
        vector<int> dp(n + 1);
        for (int i = 2; i <= n; i++)
        {
            dp[i] = dp[i - 1] * 10 + (i - 1) * (9 * pow(10, i - 2) - dp[i - 1]);
        }
        int result = 0;
        for (int i = 0; i <= n; ++i)
        {
            result += dp[i];
        }

        return pow(10, n) - result;
    }
};
